<?php
class BlogCommentsController extends AppController
{
    public $name = 'BlogComments';
    public $components = array(
        'Email'
    );
    public $uses = array(
        'BlogComment',
        'EmailTemplate'
    );
    public function beforeFilter()
    {
        if (!Configure::read('Project.is_project_update_comment_enabled')) {
            throw new NotFoundException(__l('Invalid request'));
        }
        if (!Configure::read('suspicious_detector.is_enabled') && !Configure::read('Project.auto_suspend_update_comment_on_system_flag')) {
            $this->Blog->Behaviors->detach('SuspiciousWordsDetector');
        }
        parent::beforeFilter();
    }
    public function index($blog_id = null)
    {
        $this->pageTitle = __l('Update Comments');
        $blog = $this->BlogComment->Blog->find('first', array(
            'conditions' => array(
                'Blog.id' => $blog_id
            ) ,
            'contain' => array(
                'Project' => array(
                    'User' => array(
                        'fields' => array(
                            'User.id',
                            'User.username'
                        )
                    )
                )
            ) ,
            'recursive' => 2
        ));
        if (empty($blog)) {
            throw new NotFoundException(__l('Invalid request'));
        }
        $conditions = array();
        $conditions['BlogComment.blog_id'] = $blog_id;


        if ($this->Auth->user('user_type_id') != ConstUserTypes::Admin) {
                $conditions['BlogComment.admin_suspend <>'] = 1;
        }
        $this->paginate = array(
            'conditions' => $conditions,
            'contain' => array(
                'User' => array(
                    'UserAvatar',
                    'fields' => array(
                        'User.username'
                    )
                ) ,
                'Blog' => array(
                    'fields' => array(
                        'Blog.title',
                        'Blog.slug',
                        'Blog.project_id'
                    )
                )
            ) ,
            'order' => array(
                'BlogComment.id DESC'
            ) ,
            'limit' => 10
        );
		
		if ($this->RequestHandler->prefers('json')) {
			$iphone_blog_comments = $this->paginate();
			$iphone_blog_comment = array();
			for($i=0;$i<count($iphone_blog_comments);$i++)
			{
				 $image_options = array(
            			'dimension' => 'iphone_project_thumb',
            			'class' => '',
            			'alt' => 'alt',
            			'title' => 'title',
            			'type' => 'jpg'
        		);
		
				if(!empty($iphone_blog_comments[$i]['User']['UserAvatar']))
				{
				$image_url = Router::url('/', true).$this->BlogComment->Blog->Project->getImageUrl('UserAvatar', $iphone_blog_comments[$i]['User']['UserAvatar'], $image_options);
				}
				else
				{	
				$iphone_blog_comments[$i]['User']['UserAvatar']['id'] = constant(sprintf('%s::%s', 'ConstAttachment', 'UserAvatar'));
				$image_url = Router::url('/', true).$this->BlogComment->Blog->Project->getImageUrl('UserAvatar', $iphone_blog_comments[$i]['User']['UserAvatar'], $image_options);
				}
				$iphone_blog_comment[$i]['BlogComment_id']=$iphone_blog_comments[$i]['BlogComment']['id'];
				$iphone_blog_comment[$i]['BlogComment_blog_id']=$iphone_blog_comments[$i]['BlogComment']['blog_id'];
				$iphone_blog_comment[$i]['BlogComment_created']=$iphone_blog_comments[$i]['BlogComment']['created'];
				$iphone_blog_comment[$i]['BlogComment_comment']=$iphone_blog_comments[$i]['BlogComment']['comment'];
				$iphone_blog_comment[$i]['Blog_title']=$iphone_blog_comments[$i]['Blog']['title'];
				$iphone_blog_comment[$i]['Blog_slug']=$iphone_blog_comments[$i]['Blog']['slug'];
				$iphone_blog_comment[$i]['Blog_title']=$iphone_blog_comments[$i]['Blog']['title'];
				$iphone_blog_comment[$i]['Blog_project_id']=$iphone_blog_comments[$i]['Blog']['project_id'];
				$iphone_blog_comment[$i]['User_username']=$iphone_blog_comments[$i]['User']['username'];
				$iphone_blog_comment[$i]['User_id']=$iphone_blog_comments[$i]['User']['id'];
				$iphone_blog_comment[$i]['Blogcomment_user_image']=$image_url;
				//$iphone_blog_comment[$i]['User']['UserAvatar']['filename']=$iphone_blog_comments[$i]['User']['UserAvatar']['filename'];
				//$iphone_blog_comment[$i]['User']['UserAvatar']['dir']=$iphone_blog_comments[$i]['User']['UserAvatar']['dir'];
				//$iphone_blog_comment[$i]['User']['UserAvatar']['width']=$iphone_blog_comments[$i]['User']['UserAvatar']['width'];
				//$iphone_blog_comment[$i]['User']['UserAvatar']['height']=$iphone_blog_comments[$i]['User']['UserAvatar']['height'];
			}
			$this->view = 'Json';
			$this->set('json',$iphone_blog_comment);

		}
        $this->BlogComment->recursive = 0;
        $this->set('blogComments', $this->paginate());
        $this->set('blog', $blog);
    }
    public function add()
    {
        $this->pageTitle = __l('Add Update Comment');
        $blog = array();
        if (!empty($this->request->data)) {
            $project_id = $this->BlogComment->Blog->find('first', array(
                'conditions' => array(
                    'Blog.id' => $this->request->data['BlogComment']['blog_id']
                ) ,
                'fields' => array(
                    'Blog.project_id'
                ) ,
                'recursive' => - 1,
            ));
            $this->request->data['BlogComment']['user_id'] = $this->Auth->user('id');
            $this->request->data['BlogComment']['project_id'] = $project_id['Blog']['project_id'];
			$this->request->data['BlogComment']['ip_id'] = $this->BlogComment->toSaveIp();
            $this->BlogComment->create();
            if ($this->BlogComment->save($this->request->data)) {
                $blogComment = $this->BlogComment->find('first', array(
                    'conditions' => array(
                        'BlogComment.id' => $this->BlogComment->id
                    ) ,
                    'recursive' => - 1
                ));
                $blog = $this->BlogComment->Blog->find('first', array(
                    'conditions' => array(
                        'Blog.id' => $this->request->data['BlogComment']['blog_id']
                    ) ,
                    'contain' => array(
                        'Project' => array(
                            'User' => array(
                                'fields' => array(
                                    'User.email',
                                    'User.username'
                                )
                            ) ,
                            'ProjectFund' => array(
                                'fields' => array(
                                    'ProjectFund.user_id'
                                )
                            ) ,
                            'ProjectFollower' => array(
                                'fields' => array(
                                    'ProjectFollower.user_id'
                                )
                            ) ,
                            'fields' => array(
                                'Project.id',
                                'Project.user_id',
                                'Project.name',
                                'Project.slug'
                            ) ,
                        ) ,
                    ) ,
                    'fields' => array(
                        'Blog.id',
                        'Blog.title',
                        'Blog.slug',
                        'Blog.project_id'
                    ) ,
                    'recursive' => 2
                ));
                if (!$blogComment['BlogComment']['admin_suspend']) {
                    // sending notification mail
                    $to_users = array();
                    // send mail to backed
                    $pledged_users = Set::extract('/Project/ProjectFund/user_id', $blog);
                    $pledged_user_lists = $this->_sendAlertOnUpdateComment(array_unique($pledged_users) , $blog, ConstProjectUsers::Backer);
                    // send mail to followers
                    $follow_users = Set::extract('/Project/ProjectFollower/user_id', $blog);
                    $this->_sendAlertOnUpdateComment(array_unique($follow_users) , $blog, ConstProjectUsers::Follower, $pledged_user_lists);
                    // send mail to Owner
                    $this->_sendAlertOnUpdateComment(array(
                        $blog['Project']['user_id']
                    ) , $blog, ConstProjectUsers::Owner);
                }
                if ($blogComment['BlogComment']['admin_suspend']) {
                    $this->Session->setFlash(__l('Project update Comment has been suspended due to containing suspicious words.') , 'default', null, 'error');
					if (!$this->RequestHandler->isAjax()) {
                        $this->redirect(array(
                            'controller' => 'blogs',
                            'action' => 'view',
                            $blog['Blog']['slug']
                        ));
                    } else {
                        $this->setAction('view', $this->BlogComment->id, 'view_ajax');
                    }
                } else {
                    $this->Session->setFlash(__l('Comment has been added for project updates') , 'default', null, 'success');
                    if (!$this->RequestHandler->isAjax()) {
                        $this->redirect(array(
                            'controller' => 'blogs',
                            'action' => 'view',
                            $blog['Blog']['slug']
                        ));
                    } else {
                        $this->setAction('view', $this->BlogComment->id, 'view_ajax');
                    }
                    $this->set('blogComment', $blogComment);
                }
            } else {
                $this->Session->setFlash(__l('Comment could not be added for project updates. Please, try again.') , 'default', null, 'error');
            }
            $this->set('blog', $blog);
        }
        if (!empty($this->request->params['named']['blog_id'])) {
            $this->request->data['BlogComment']['blog_id'] = $this->request->params['named']['blog_id'];
        }
    }
    public function view($id = null, $view_name = 'view')
    {
        $this->pageTitle = __l('Update Comment');
        if (is_null($id)) {
            throw new NotFoundException(__l('Invalid request'));
        }
        $blogComment = $this->BlogComment->find('first', array(
            'conditions' => array(
                'BlogComment.id = ' => $id,
            ) ,
            'contain' => array(
                'User' => array(
                    'UserAvatar' => array(
                        'fields' => array(
                            'UserAvatar.id',
                            'UserAvatar.dir',
                            'UserAvatar.filename'
                        )
                    ) ,
                    'fields' => array(
                        'User.username'
                    )
                ) ,
                'Blog' => array(
                    'Project' => array(
                        'fields' => array(
                            'Project.user_id',
                        )
                    ) ,
                    'fields' => array(
                        'Blog.title',
                        'Blog.slug',
                        'Blog.project_id',
                        'Blog.id'
                    )
                )
            ) ,
            'recursive' => 2,
        ));
        if (empty($blogComment)) {
            throw new NotFoundException(__l('Invalid request'));
        }
        $this->pageTitle.= ' - ' . $blogComment['BlogComment']['id'];
        $this->set('blogComment', $blogComment);
        if ($view_name == 'view') {
            $this->autoRender = false;
        } else {
            $this->render($view_name);
        }
    }
    public function _sendAlertOnUpdateComment($to_users, $blog, $projectUserType, $user_lists = array())
    {
        if (!empty($to_users)) {
            $users = $this->BlogComment->User->find('all', array(
                'conditions' => array(
                    'User.id' => $to_users
                ) ,
                'fields' => array(
                    'User.id',
                    'User.email',
                    'User.username',
                ) ,
                'recursive' => - 1
            ));
            // Send private messsage on project comment add
            $subject = __l('New Project Update Comment');
            $message = $this->Auth->User('username') . ' ' . __l('has commented on update in project') . ' "' . $blog['Project']['name'] . '"';
            $message_id = $this->BlogComment->Blog->Project->Message->sendNotifications($to_users, $subject, $message, $blog['Project']['id']);
            foreach($users as $user) {
                if (!in_array($user['User']['id'], $user_lists)) {
                    $user_preference = $this->BlogComment->_getPermissionPerference($user['User']['id']);
                    if (($projectUserType == ConstProjectUsers::Backer && $user_preference['UserPermissionPreference']['project_blog_comment_mail_send_backer'] == 1) || ($projectUserType == ConstProjectUsers::Follower && $user_preference['UserPermissionPreference']['project_blog_comment_mail_send_follower'] == 1) || ($projectUserType == ConstProjectUsers::Owner && $user_preference['UserPermissionPreference']['project_blog_comment_mail_send_owner'] == 1)) {
                        $email_message = $this->EmailTemplate->selectTemplate('Project Update Comment Add Alert');
                        $emailFindReplace = array(
                            '##FROM_EMAIL##' => $this->BlogComment->changeFromEmail(($email_message['from'] == '##FROM_EMAIL##') ? Configure::read('EmailTemplate.from_email') : $email_message['from']) ,
                            '##USERNAME##' => $user['User']['username'],
                            '##USER##' => $this->Auth->User('username') ,
                            '##SITE_NAME##' => Configure::read('site.name') ,
                            '##PROJECT_NAME##' => $blog['Project']['name'],
                            '##BLOG_TITLE##' => $blog['Blog']['title'],
                            '##BLOG_LINK##' => Router::url(array(
                                'controller' => 'blogs',
                                'action' => 'view',
                                $blog['Blog']['slug'],
                                'admin' => false
                            ) , true) ,
                            '##SITE_URL##' => Router::url('/', true) ,
                        );
                        $this->Email->from = ($email_message['from'] == '##FROM_EMAIL##') ? Configure::read('EmailTemplate.from_email') : $email_message['from'];
                        $this->Email->replyTo = ($email_message['reply_to'] == '##REPLY_TO_EMAIL##') ? Configure::read('EmailTemplate.reply_to_email') : $email_message['reply_to'];
                        $this->Email->to = $user['User']['email'];
                        $this->Email->subject = strtr($email_message['subject'], $emailFindReplace);
                        $this->Email->sendAs = !empty($email_message['is_html']) ? 'html' : 'text';
                        $this->Email->send(strtr($email_message['email_content'], $emailFindReplace));
                    }
                    $user_lists[] = $user['User']['id'];
                }
            }
        }
        return $user_lists;
    }
    public function delete($id = null)
    {
        if (is_null($id)) {
            throw new NotFoundException(__l('Invalid request'));
        }
        $blog = $this->BlogComment->find('first', array(
            'conditions' => array(
                'BlogComment.id' => $id
            ) ,
            'fields' => array(
                'Blog.slug'
            ) ,
            'recursive' => 0
        ));
        if (empty($blog)) {
            throw new NotFoundException(__l('Invalid request'));
        }
        if ($this->BlogComment->delete($id)) {
            $this->Session->setFlash(__l('Project update Comment deleted') , 'default', null, 'success');
            if (!$this->RequestHandler->isAjax()) {
                $this->redirect(array(
                    'controller' => 'blogs',
                    'action' => 'view',
                    $blog['Blog']['slug']
                ));
            } else {
                echo 'success';
                exit;
            }
        } else {
            throw new NotFoundException(__l('Invalid request'));
        }
    }
    public function admin_index()
    {
        $this->pageTitle = __l('Project Update Comments');
        $this->_redirectGET2Named(array(
            'q'
        ));
        $this->pageTitle = __l('Project Update Comments');
        $conditions = array();
        if (!empty($this->request->params['named']['blog']) || !empty($this->request->params['named']['blog'])) {
            $blog = $this->{$this->modelClass}->Blog->find('first', array(
                'conditions' => array(
                    'Blog.id' => $this->request->params['named']['blog']
                ) ,
                'fields' => array(
                    'Blog.id',
                    'Blog.title',
                    'Blog.slug'
                ) ,
                'recursive' => - 1
            ));
            if (empty($blog)) {
                throw new NotFoundException(__l('Invalid request'));
            }
            $conditions['Blog.id'] = $blog['Blog']['id'];
            $this->pageTitle.= sprintf(__l(' - Project Update - %s') , $blog['Blog']['title']);
        }
        if (isset($this->request->params['named']['filter_id'])) {
            $this->request->data['BlogComment']['filter_id'] = $this->request->params['named']['filter_id'];
        }
        if (!empty($this->request->data['BlogComment']['filter_id'])) {
            if ($this->request->data['BlogComment']['filter_id'] == ConstMoreAction::Suspend) {
                $conditions['BlogComment.admin_suspend'] = 1;
                $this->pageTitle.= __l(' - Suspend ');
            } elseif ($this->request->data['BlogComment']['filter_id'] == ConstMoreAction::Flagged) {
                $conditions['BlogComment.is_system_flagged'] = 1;
                $this->pageTitle.= __l(' - Flagged ');
            }
            $this->request->params['named']['filter_id'] = $this->request->data['BlogComment']['filter_id'];
        }
        if (!empty($this->request->params['named']['username'])) {
            $conditions['User.username'] = $user['User']['username'];
            $this->pageTitle.= sprintf(__l(' - User - %s') , $user['User']['username']);
        }
        if (isset($this->request->params['named']['stat']) && $this->request->params['named']['stat'] == 'day') {
            $conditions['TO_DAYS(NOW()) - TO_DAYS(BlogComment.created) <= '] = 0;
            $this->pageTitle.= __l(' - Commented today');
        }
        if (isset($this->request->params['named']['stat']) && $this->request->params['named']['stat'] == 'week') {
            $conditions['TO_DAYS(NOW()) - TO_DAYS(BlogComment.created) <= '] = 7;
            $this->pageTitle.= __l(' - Commented in this week');
        }
        if (isset($this->request->params['named']['stat']) && $this->request->params['named']['stat'] == 'month') {
            $conditions['TO_DAYS(NOW()) - TO_DAYS(BlogComment.created) <= '] = 30;
            $this->pageTitle.= __l(' - Commented in this month');
        }
        if (!empty($this->request->params['named']['q'])) {
            $this->request->data['BlogComment']['q'] = $this->request->params['named']['q'];
            $blog_ids  = array();
            $projects = $this->BlogComment->Blog->Project->find('all', array(
                'conditions' => array(
                    'Project.name like ' => '%' . $this->request->data['BlogComment']['q'] . '%',
					'Project.is_active ' => 1
                ) ,
	            'contain' => array(
	                'Blog' => array(
                        'fields' => array(
                            'Blog.id'
                        )
	                )
	            ),
                'fields' => array(
                    'Project.id'
                ) ,
                'recursive' => 1
            ));
			if (!empty($projects)) {
                foreach($projects as $project) {
                    foreach($project['Blog'] as $blog) {
                        $blog_ids[] = $blog['id'];
                        }
                }
            }
            $this->pageTitle.= sprintf(__l(' - Search - %s') , $this->request->params['named']['q']);
			$conditions['OR'] = array('BlogComment.comment LIKE' => '%' . $this->request->data['BlogComment']['q'] . '%',
									  'Blog.title LIKE' => '%' . $this->request->data['BlogComment']['q'] . '%',
									  'Blog.slug LIKE' => '%' . $this->request->data['BlogComment']['q'] . '%',
									  'BlogComment.blog_id ' => $blog_ids,
									 );
        }
        $this->paginate = array(
            'conditions' => $conditions,
            'contain' => array(
                'User' => array(
                    'UserAvatar' => array(
                        'fields' => array(
                            'UserAvatar.id',
                            'UserAvatar.dir',
                            'UserAvatar.filename',
                            'UserAvatar.width',
                            'UserAvatar.height'
                        )
                    ) ,
                    'fields' => array(
                        'User.username'
                    )
                ) ,
				'Ip' => array(
                    'City' => array(
                        'fields' => array(
                            'City.name',
                        )
                    ) ,
                    'State' => array(
                        'fields' => array(
                            'State.name',
                        )
                    ) ,
                    'Country' => array(
                        'fields' => array(
                            'Country.name',
                            'Country.iso2',
                        )
                    ) ,
                    'fields' => array(
                        'Ip.ip',
                        'Ip.latitude',
                        'Ip.longitude',
						'Ip.host'
                    )
                ) ,
                'Blog' => array(
                    'Project' => array(
                        'fields' => array(
                            'Project.id',
                            'Project.name',
                            'Project.slug',
                        ) ,
                        'ProjectStatus',
                    ) ,
                    'fields' => array(
                        'Blog.title',
                        'Blog.slug',
                        'Blog.user_id',
                        'Blog.project_id'
                    ) ,
                ) ,
            ) ,
            'order' => array(
                'BlogComment.id' => 'DESC'
            )
        );
        $this->set('suspended', $this->BlogComment->find('count', array(
            'conditions' => array(
                'BlogComment.admin_suspend = ' => 1,
            )
        )));
        $this->set('system_flagged', $this->BlogComment->find('count', array(
            'conditions' => array(
                'BlogComment.is_system_flagged = ' => 1,
            )
        )));
        $this->BlogComment->recursive = 1;
        $moreActions = $this->BlogComment->moreActions;
        $this->set(compact('moreActions'));
        $this->set('blogComments', $this->paginate());
    }
    public function admin_delete($id = null)
    {
        if (is_null($id)) {
            throw new NotFoundException(__l('Invalid request'));
        }
        if ($this->BlogComment->delete($id)) {
            $this->Session->setFlash(__l('Project update Comment deleted') , 'default', null, 'success');
            $this->redirect(array(
                'controller' => 'blog_comments',
                'action' => 'index',
            ));
        } else {
            throw new NotFoundException(__l('Invalid request'));
        }
    }
    public function admin_update()
    {
        if (!empty($this->request->data[$this->modelClass])) {
            $this->BlogComment->Behaviors->detach('Logable');
            $r = $this->request->data[$this->modelClass]['r'];
            $actionid = $this->request->data[$this->modelClass]['more_action_id'];
            unset($this->request->data[$this->modelClass]['r']);
            unset($this->request->data[$this->modelClass]['more_action_id']);
            $selectedIds = array();
            foreach($this->request->data[$this->modelClass] as $primary_key_id => $is_checked) {
                if ($is_checked['id']) {
                    $selectedIds[] = $primary_key_id;
                }
            }
            if ($actionid && !empty($selectedIds)) {
                if ($actionid == ConstMoreAction::Delete) {
                    $this->{$this->modelClass}->deleteAll(array(
                        $this->modelClass . '.id' => $selectedIds
                    ));
                    $this->Session->setFlash(__l('Checked project update comments has been deleted') , 'default', null, 'success');
                } else if ($actionid == ConstMoreAction::Suspend) {
                    foreach($selectedIds as $val) {
                        $blogComment['BlogComment']['admin_suspend'] = 1;
                        $blogComment['BlogComment']['id'] = $val;
                        $this->BlogComment->save($blogComment, false);
                    }
                    $this->Session->setFlash(__l('Checked project update comments has been Suspended') , 'default', null, 'success');
                } else if ($actionid == ConstMoreAction::Unsuspend) {
                    foreach($selectedIds as $val) {
                        $blogComment['BlogComment']['admin_suspend'] = 0;
                        $blogComment['BlogComment']['id'] = $val;
                        $this->BlogComment->save($blogComment, false);
                    }
                    $this->Session->setFlash(__l('Checked project update comments has been Unsuspended') , 'default', null, 'success');
                } else if ($actionid == ConstMoreAction::Flagged) {
                    $this->BlogComment->updateAll(array(
                        'BlogComment.is_system_flagged' => 1
                    ) , array(
                        'BlogComment.id' => $selectedIds
                    ));
                    $this->Session->setFlash(__l('Checked project update comments has been Flagged') , 'default', null, 'success');
                } else if ($actionid == ConstMoreAction::Unflagged) {
                    $this->BlogComment->updateAll(array(
                        'BlogComment.is_system_flagged' => 0
                    ) , array(
                        'BlogComment.id' => $selectedIds
                    ));
                    $this->Session->setFlash(__l('Checked project update comments has been Unflagged') , 'default', null, 'success');
                }
            }
        }
        $this->redirect(Router::url('/', true) . $r);
    }
    public function admin_update_stats($id = null)
    {
        if (is_null($id)) {
            throw new NotFoundException(__l('Invalid request'));
        }
        $this->BlogComment->Behaviors->detach('Logable');
        $this->BlogComment->Behaviors->detach('SuspiciousWordsDetector');
        if (!empty($this->request->params['named']['flag']) && ($this->request->params['named']['flag'] == 'active')) {
            $this->BlogComment->updateAll(array(
                'BlogComment.is_system_flagged' => 1
            ) , array(
                'BlogComment.id' => $id
            ));
            $this->Session->setFlash(__l('Project update comment has been flagged') , 'default', null, 'success');
        } elseif (!empty($this->request->params['named']['flag']) && ($this->request->params['named']['flag'] == 'deactivate')) {
            $this->BlogComment->updateAll(array(
                'BlogComment.is_system_flagged' => 0
            ) , array(
                'BlogComment.id' => $id
            ));
            $this->Session->setFlash(__l('Project update comment has been Unflagged') , 'default', null, 'success');
        } elseif (!empty($this->request->params['named']['flag']) && ($this->request->params['named']['flag'] == 'suspend')) {
            // refund amount
            $blogComment['BlogComment']['admin_suspend'] = 1;
            $blogComment['BlogComment']['id'] = $id;
            $this->BlogComment->save($blogComment['BlogComment']);
            $this->Session->setFlash(__l('Project update comment has been suspend') , 'default', null, 'success');
        } elseif (!empty($this->request->params['named']['flag']) && ($this->request->params['named']['flag'] == 'unsuspend')) {
            $blogComment = array();
            $blogComment['BlogComment']['admin_suspend'] = 0;
            $blogComment['BlogComment']['id'] = $id;
            $this->BlogComment->save($blogComment['BlogComment'], false);
            $this->Session->setFlash(__l('Project update comment has been unsuspend') , 'default', null, 'success');
        }
        $this->redirect(array(
            'action' => 'index',
        ));
    }
}
?>